var lastX = 0;//must conform to imgSheet left, PLUS distance to first note
var lastY = 0;//must conform to imgSheet left, PLUS distance to first note

function loadBody()
{
	
}
function cancelDefault()
{
	window.event.returnValue = false;
	return false;
}
function doNote(objImg, evt)
{
	var root =  document.body; 
	var mx = evt.pageX || evt.clientX + root.scrollLeft; 
	var my = evt.pageY || evt.clientY + root.scrollTop; 

	addNote(mx, my);
	return false;	
}

if (document.layers)
	document.captureEvents(Event.KEYUP);
document.onkeyup = function (evt)
{
	var nav4up = document.layers ? true : false; 
	var keyValue = nav4up ? e.which : event.keyCode; 

	var keyCharValue = String.fromCharCode(keyValue); 

	switch (keyCharValue.toLowerCase())
	{
		case "a":	
		{
lastY = 225;
addNote(lastX, lastY);
			break;
		}
		case "b":	
		{
lastY = 223;
addNote(lastX, lastY);
			break;
		}
		case "c":	
		{
lastY = 220;
addNote(lastX, lastY);
			break;
		}
		case "d":	
		{
lastY = 217;
addNote(lastX, lastY);
			break;
		}
		case "e":	
		{
lastY = 215;
addNote(lastX, lastY);
			break;
		}
	}	
} 
function addNote(inX, inY)
{
	var root =  document.body; 
	var img = document.createElement("IMG");
	img.style.position = "absolute";
	img.style.left = inX-3+"px"; 
	img.style.top = inY-17+"px"; 
	img.style.width="12px";
	img.style.height="20px";
	img.src = "images/note.gif"; 
//Need to add "notename" based on co-ords.
	img.noteName = getNoteName(inY);
//alert("" + inY + ", " + img.noteName);
	img.id = "arrNotes";
	img.name = "arrNotes";
	img.onmouseup = function()
	{
		root.removeChild(this);
		var charCounter = document.getElementById("charCount");
		var iCount = parseInt(charCounter.innerHTML);
		iCount++;
		charCounter.innerHTML = iCount;

		return false;
	};
	root.appendChild(img);

	var charCounter = document.getElementById("charCount");
	var iCount = parseInt(charCounter.innerHTML);
	iCount--;
	charCounter.innerHTML = iCount;

	lastX=  inX + 14;
	lastY = inY;
}
function getNoteName(y)
{
	if (y<208)
		return "f";
	else if (y<211)
		return "e";
	else if (y<213)
		return "d";
	else if (y<216)
		return "c";
	else if (y<218)
		return "b";
	else if (y<221)
		return "a";
	else if (y<223)
		return "g";
	else if (y<226)
		return "f";
	else if (y<228)
		return "e";
	else if (y<231)
		return "d";
	else
		return "c";
}
function buildSearchStringFromImage()
{
	var strRes = "";

	var a = new Array();
	var elNotes;
	elNotes = document.getElementsByName("arrNotes");
//	for (var i=0;i<arrNotes.length;i++)
//		a.push(arrNotes[i]);

	for (var i=0;i<elNotes.length;i++)
		a.push(elNotes[i]);

	a.sort(mysortfn);
	
	for (i=0;i<a.length;i++)
		strRes+= a[i].noteName;

	var qry;
	if (document.getElementById)
	{
		qry=document.getElementById('query');		
		qry.value = strRes;
	}
	else
		entrybox.query.value = strRes;
alert(strRes);
	return strRes;
}
function mysortfn(a, b)
{
	if (a.style.posLeft<b.style.posLeft) return  -1;
	if (a.style.posLeft>b.style.posLeft) return 1;
	if (a.style.posLeft==b.style.posLeft)
	{
		if (a.style.posTop<b.style.posTop)
			return -1;
		if (a.style.posTop>b.style.posTop)
			return 1;
		return 0;
	}
	return 0;
}
function buildImageFromSearchString()
{
} 
